package cn.lyq.card.ui.statistics

import android.view.View
import androidx.lifecycle.Observer
import cn.lyq.card.R
import cn.lyq.card.base.BaseActivity
import cn.lyq.card.data.src.Status
import cn.lyq.card.utils.setClick
import com.blankj.utilcode.util.ToastUtils
import kotlinx.android.synthetic.main.act_statistics_all.*
import kotlinx.android.synthetic.main.layout_title.*


class StatisticsAllActivity : BaseActivity() {

    private val mModel by lazy {
        getVM(StatisticsVM::class.java)
    }

    override fun getLayoutId(): Int {
        return R.layout.act_statistics_all
    }

    override fun initView() {
        super.initView()
        setMyTitle(R.string.str_device_statistics)
        tvTitleSplit.visibility = View.GONE

        bgPerson.setClick {
            DeviceStatisticActivity.start(this, 0)
        }
        bgTeam.setClick {
            DeviceStatisticActivity.start(this, 1)
        }
    }

    override fun initObserver() {
        super.initObserver()
        mModel.posCount().observe(this, Observer {
            when (it?.status) {
                Status.LOADING -> showLoading()
                Status.SUCCESS -> {
                    it.requireData().let { info ->
                        tvPersonAmount.text = info.posNumber.toString()
                        tvPersonActive.text = "已激活台数：${info.posActNumber}"
                        tvPersonUnActive.text = "未激活台数：${info.posNotActNumber}"

                        tvTeamAmount.text = info.posTeamNumber.toString()
                        tvTeamActive.text = "已激活台数：${info.posTeamActNumber}"
                        tvTeamUnActive.text = "未激活台数：${info.posTeamNotActNumber}"
                    }
                    dismissLoading()
                }
                Status.ERROR -> {
                    ToastUtils.showShort(it.message.getMsg())
                    dismissLoading()
                }
            }
        })
    }
}